package com.dasel.math

import static groovyx.gpars.Parallelizer.*
import org.junit.Test
import groovyx.gpars.ParallelArrayUtil

class Benchmark {

    @Test
	void main() {
		int cols = 5000
		int rows = 5000
		def start = System.currentTimeMillis()
		def guassian = ProbabilitySpace.createQuasiGaussian(rows,cols)
		def speed = (System.currentTimeMillis() - start)/1000.0
		println "Speed to generated the gaussian: $speed"

        //test("Grid", new Grid(matrix:guassian.data, rows:rows, cols:cols))
		test("Jrid", new Jrid(guassian.data, rows, cols))
		//test("Srid", new Srid<BigDecimal>(matrix:guassian.data, rows:rows, cols:cols))
		//test("Drid", new Drid(matrix:guassian.data, rows:rows, cols:cols))
		//test("Prid", new Prid(matrix:guassian.data, rows:rows, cols:cols))
		test("Vrid", new Vrid(matrix:guassian.data, rows:rows, cols:cols))
		test("Asrid", new Asrid(matrix:guassian.data, rows:rows, cols:cols))
		test("NumericGrid", new NumericGrid(guassian.data, rows, cols))
	}

    void test(name, grid) {
        def tmp = null
		def benchmarks = []
		30.times {
			doParallel(10) {
                def start = System.currentTimeMillis()
                if (tmp == null) {
                   tmp = grid * 2 + 4
                } else {
                   tmp = (tmp * grid) + grid
                }
				def speed = (System.currentTimeMillis() - start)/1000.0
				benchmarks <<  speed
			}
		}
		println "$name: Best Time is ${benchmarks.min()} worst time is ${benchmarks.max()} total time is ${benchmarks.sum()}"
	}
}